package com.lhkj.ct.admin.modules.patient.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.Option;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.base.validator.group.ValGroups;
import com.lhkj.ct.meta.modules.patient.model.entity.TblPatCrowdTag;
import com.lhkj.ct.meta.modules.patient.service.PatCrowdTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 档案人群标签 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2023-09-25
 */
@RestController
@RequestMapping("api/plat/patient/crowd/tag")
@Api(tags = {"1.3标签维护"})
@Validated
public class PatCrowdTagController {

    @Resource
    private PatCrowdTagService patCrowdTagService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "标签分页")
    @GetMapping("list")
    //@RequiresPermissions(value = {"system:patTag:list"})
    public ActionResult<IPage<TblPatCrowdTag>> all(TblPatCrowdTag queryParams, PageQuery pageQuery) {
        return ActionResult.success(patCrowdTagService.selectCrowdTagPage(queryParams, pageQuery));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "所有标签")
    @GetMapping("options")
    public ActionResult<List<Option<String>>> all() {
        return ActionResult.success(patCrowdTagService.listOptions());
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "标签详情")
    @GetMapping("{tagId}")
    //@RequiresPermissions(value = {"system:patTag:get", "system:patTag:update"}, logical = Logical.OR)
    public ActionResult<TblPatCrowdTag> all(@PathVariable String tagId) {
        return ActionResult.success(patCrowdTagService.getById(tagId));
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增")
    @PostMapping("insert")
    @Log(title = "标签维护", actionType = ActionType.INSERT)
    //@RequiresPermissions(value = {"system:patTag:insert"}, logical = Logical.OR)
    public ActionResult<Void> insert(@Validated(ValGroups.Insert.class) @RequestBody TblPatCrowdTag crowdTag) {
        return ActionResult.judge(patCrowdTagService.insert(crowdTag));
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改")
    @PostMapping("update")
    @Log(title = "标签维护", actionType = ActionType.UPDATE)
    //@RequiresPermissions(value = {"system:patTag:update"})
    public ActionResult<Void> update(@Validated(ValGroups.Update.class) @RequestBody TblPatCrowdTag crowdTag) {
        return ActionResult.judge(patCrowdTagService.updateById(crowdTag));
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "删除")
    @DeleteMapping("delete")
    @Log(title = "标签维护", actionType = ActionType.DELETE)
    //@RequiresPermissions(value = {"system:patTag:delete"})
    public ActionResult<Void> delete(@NotEmpty(message = "标签id不能为空") @RequestBody List<String> ids) {
        return ActionResult.judge(patCrowdTagService.removeByIds(ids));
    }
}
